{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-12-26T16:47:04.999800Z",
     "start_time": "2017-12-26T16:47:04.031936Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "213 74 Twin Rm@Jordan TST Kowloon West #7 独立房间 1室1卫2床\n",
      "0 155 福田购物公园会展中心零距离~星河国际花园温馨高品质三房,楼下是地铁三号及一号线,对面是平安金融中心 整套公寓 3室2卫3床\n",
      "0 57 福田车公庙下沙地铁口东南亚大床房民宿整租 整套房子 1室1卫2床\n",
      "0 42 布吉双地铁换乘站、近罗湖/深圳北站清新公寓 整套公寓 1室1卫1床\n",
      "0 58 近中广核大厦/希尔顿酒店/会展中心温馨公寓 in Futian CBD 整套公寓 1室1卫1床\n",
      "0 75 福田CBD,近会展中心车公庙,整套四房 整套公寓 4室1卫4床\n",
      "3 126 一处面朝大海的地方——近海上世界 港澳游出行方便 整套房子 3室2卫3床\n",
      "0 157 浪漫小屋高端民宿 整套酒店式公寓 单间1卫2床\n",
      "0 78 601近会展中心,岗厦地铁站200米,豪华套房公寓 整套房子 1室1卫1床\n",
      "0 217 莲花山 整套公寓 1室2卫1床\n",
      "5 203 【食物·森林】南山CBD.毗邻世界之窗&欢乐谷&华侨城.临地铁1号线世界之窗站.温馨复式花园4BDR 整套公寓 4室1卫4床\n",
      "4 97 (今日特惠)【情愫·蓝桥】福田CBD.毗邻会展中心&皇岗口岸&福田站.临近7号线石厦站舒适3BDR 整套公寓 3室1卫3床\n",
      "7 37 超大独卫双人房-会展中心购物公园皇岗*Y-HOUSE 独立房间 1室1卫2床\n",
      "7 37 Futian CBD nice apartment 福田CBD中心区双地铁口精致公寓 整套公寓 单间1卫1床\n",
      "2条评价 24 开业特惠【Little holiday-2】KK Mall城市景观private bedroom 独立房间 1室1卫1床\n",
      "65 40 (云意)罗湖阅见·生活美学公寓城景大床房近地王大厦万象城KKMALL大剧院D出口 整套公寓 1室1卫1床\n",
      "7 115 Shanghai Shanghai (Two bedroom) 整套公寓 2室1卫2床\n",
      "7 61 无间-海上世界别墅#PINK#地铁站边#超大天台#独立卫浴阳台#蛇口港#近深圳湾口岸 独立房间 1室1卫1床\n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.firefox.firefox_binary import FirefoxBinary\n",
    "import time\n",
    "\n",
    "caps = webdriver.DesiredCapabilities().FIREFOX\n",
    "caps[\"marionette\"] = True\n",
    "binary = FirefoxBinary(r'D:\\Program Files\\Mozilla Firefox\\firefox.exe')\n",
    "#把上述地址改成你电脑中Firefox程序的地址\n",
    "\n",
    "#用 selenium 的 driver 来启动 firefox\n",
    "driver = webdriver.Firefox(firefox_binary=binary, capabilities=caps)\n",
    "#在虚拟浏览器中打开 Airbnb 页面\n",
    "driver.get(\"https://zh.airbnb.com/s/Shenzhen--China?page=1\")\n",
    "\n",
    "#找到页面中所有的出租房\n",
    "rent_list = driver.find_elements_by_css_selector('div._1788tsr0')\n",
    "\n",
    "#对于每一个出租房\n",
    "for eachhouse in rent_list:\n",
    "    #找到评论数量\n",
    "    try:\n",
    "        comment = eachhouse.find_element_by_css_selector('span._gb7fydm')\n",
    "        comment = comment.text\n",
    "    except:\n",
    "        comment = 0\n",
    "    \n",
    "    #找到价格\n",
    "    price = eachhouse.find_element_by_css_selector('span._hylizj6')\n",
    "    price = price.text[4:]\n",
    "    \n",
    "    #找到名称\n",
    "    name = eachhouse.find_element_by_css_selector('div._ew0cqip')\n",
    "    name = name.text\n",
    "    \n",
    "    #找到房屋类型，大小\n",
    "    details = eachhouse.find_elements_by_css_selector('div._saba1yg small div span')\n",
    "    details = details[0].text\n",
    "    house_type = details.split(\" · \")[0]\n",
    "    bed_number = details.split(\" · \")[1]\n",
    "    print (comment, price, name, house_type, bed_number)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-12-26T17:15:18.926225Z",
     "start_time": "2017-12-26T17:14:20.898041Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "213 74 Twin Rm@Jordan TST Kowloon West #7 独立房间 1室1卫2床\n",
      "0 155 福田购物公园会展中心零距离~星河国际花园温馨高品质三房,楼下是地铁三号及一号线,对面是平安金融中心 整套公寓 3室2卫3床\n",
      "0 57 福田车公庙下沙地铁口东南亚大床房民宿整租 整套房子 1室1卫2床\n",
      "0 42 布吉双地铁换乘站、近罗湖/深圳北站清新公寓 整套公寓 1室1卫1床\n",
      "0 58 近中广核大厦/希尔顿酒店/会展中心温馨公寓 in Futian CBD 整套公寓 1室1卫1床\n",
      "0 75 福田CBD,近会展中心车公庙,整套四房 整套公寓 4室1卫4床\n",
      "3 126 一处面朝大海的地方——近海上世界 港澳游出行方便 整套房子 3室2卫3床\n",
      "0 157 浪漫小屋高端民宿 整套酒店式公寓 单间1卫2床\n",
      "0 78 601近会展中心,岗厦地铁站200米,豪华套房公寓 整套房子 1室1卫1床\n",
      "0 217 莲花山 整套公寓 1室2卫1床\n",
      "5 203 【食物·森林】南山CBD.毗邻世界之窗&欢乐谷&华侨城.临地铁1号线世界之窗站.温馨复式花园4BDR 整套公寓 4室1卫4床\n",
      "6 94 【年底大促】【近深圳北、华为】五和地铁站+园林式小区+欧式简约风+温馨豪华四房+小鹿之家 整套房子 4室2卫4床\n",
      "7 37 超大独卫双人房-会展中心购物公园皇岗*Y-HOUSE 独立房间 1室1卫2床\n",
      "2条评价 24 开业特惠【Little holiday-2】KK Mall城市景观private bedroom 独立房间 1室1卫1床\n",
      "4 97 (今日特惠)【情愫·蓝桥】福田CBD.毗邻会展中心&皇岗口岸&福田站.临近7号线石厦站舒适3BDR 整套公寓 3室1卫3床\n",
      "46 52 (浮生)罗湖阅见·生活美学公寓城景大床房近地王大厦万象城KKMALL大剧院D出口 整套公寓 1室1卫1床\n",
      "7 37 Futian CBD nice apartment 福田CBD中心区双地铁口精致公寓 整套公寓 单间1卫1床\n",
      "10 18 爱丽丝的浪漫小窝 独立房间 1室1卫1床\n",
      "0 149 临近深圳北站 全新中式3房200平豪宅 花园泳池 静谧山景 度假休闲商务 整套公寓 3室2卫3床\n",
      "0 42 (民国复古)罗湖阅见·生活美学公寓城景大床房近地王大厦万象城KKMALL大剧院D出口 整套公寓 1室1卫1床\n",
      "10 18 爱丽丝的浪漫小窝 独立房间 1室1卫1床\n",
      "0 217 莲花山 整套公寓 1室2卫1床\n",
      "6 94 【年底大促】【近深圳北、华为】五和地铁站+园林式小区+欧式简约风+温馨豪华四房+小鹿之家 整套房子 4室2卫4床\n",
      "1条评价 66 福田CBD双床轻奢套房 整套公寓 单间1卫2床\n",
      "25 21 深圳北站 大床房 直达香港口岸/出差首选 温馨舒适北欧风公寓 独立房间 1室1卫1床\n",
      "7 115 Shanghai Shanghai (Two bedroom) 整套公寓 2室1卫2床\n",
      "0 105 会展中心、购物公园、福田口岸的豪华三居房 独立房间 3室2卫3床\n",
      "7 61 【MissY's houseY小姐的家】Well-appointed Apt福田口岸会展中心购物公园 整套公寓 1室1卫2床\n",
      "48 46 【十二微邸】32Q-KKmall楼上的天空微城堡 整套公寓 1室1卫1床\n",
      "5 30 [Y-HOUSE]工业风大床房-会展中心购物公园皇岗口岸 独立房间 1室1卫1床\n",
      "4 63 无间-海上世界别墅#BLACK#地铁站边#超大天台#独立卫浴阳台#超大浴缸#蛇口港#近深圳湾口岸 独立房间 1室1卫1床\n",
      "22 58 #从今以后#FNO1.#摄影主题民宿#深圳华侨城#生态北欧民宿#ROOM4 独立房间 1室1卫1床\n",
      "55 61 #一间设计·寒舍Room3# 拍摄请另咨询 独立房间 1室1卫1床\n",
      "0 157 浪漫小屋高端民宿 整套酒店式公寓 单间1卫2床\n",
      "21 52 福田CBD岗夏地铁旁会展中心现代公寓 整套公寓 1室1卫1床\n",
      "0 54 福田车公庙下沙地铁口轻奢极简风民宿 独立房间 1室1卫1床\n",
      "0 149 临近深圳北站 全新中式3房200平豪宅 花园泳池 静谧山景 度假休闲商务 整套公寓 3室2卫3床\n",
      "0 42 (民国复古)罗湖阅见·生活美学公寓城景大床房近地王大厦万象城KKMALL大剧院D出口 整套公寓 1室1卫1床\n",
      "10 18 爱丽丝的浪漫小窝 独立房间 1室1卫1床\n",
      "0 217 莲花山 整套公寓 1室2卫1床\n",
      "6 94 【年底大促】【近深圳北、华为】五和地铁站+园林式小区+欧式简约风+温馨豪华四房+小鹿之家 整套房子 4室2卫4床\n",
      "1条评价 66 福田CBD双床轻奢套房 整套公寓 单间1卫2床\n",
      "25 21 深圳北站 大床房 直达香港口岸/出差首选 温馨舒适北欧风公寓 独立房间 1室1卫1床\n",
      "7 115 Shanghai Shanghai (Two bedroom) 整套公寓 2室1卫2床\n",
      "0 105 会展中心、购物公园、福田口岸的豪华三居房 独立房间 3室2卫3床\n",
      "7 61 【MissY's houseY小姐的家】Well-appointed Apt福田口岸会展中心购物公园 整套公寓 1室1卫2床\n",
      "48 46 【十二微邸】32Q-KKmall楼上的天空微城堡 整套公寓 1室1卫1床\n",
      "5 30 [Y-HOUSE]工业风大床房-会展中心购物公园皇岗口岸 独立房间 1室1卫1床\n",
      "4 63 无间-海上世界别墅#BLACK#地铁站边#超大天台#独立卫浴阳台#超大浴缸#蛇口港#近深圳湾口岸 独立房间 1室1卫1床\n",
      "22 58 #从今以后#FNO1.#摄影主题民宿#深圳华侨城#生态北欧民宿#ROOM4 独立房间 1室1卫1床\n",
      "55 61 #一间设计·寒舍Room3# 拍摄请另咨询 独立房间 1室1卫1床\n",
      "0 157 浪漫小屋高端民宿 整套酒店式公寓 单间1卫2床\n",
      "21 52 福田CBD岗夏地铁旁会展中心现代公寓 整套公寓 1室1卫1床\n",
      "0 54 福田车公庙下沙地铁口轻奢极简风民宿 独立房间 1室1卫1床\n",
      "40 57 马卡龙的奇妙幻想 整套公寓 1室1卫1床\n",
      "65 40 (云意)罗湖阅见·生活美学公寓城景大床房近地王大厦万象城KKMALL大剧院D出口 整套公寓 1室1卫1床\n",
      "34 55 福田CBD简约舒适风格公寓 整套公寓 单间1卫1床\n",
      "19 42 主卧「BON」福田近会展中心、福田皇岗双口岸、岗厦地铁口附近,带暖气 独立房间 1室1卫1床\n",
      "0 203 深圳瑞吉酒店 整间精品酒店 1室2卫1床\n",
      "51 39 福田中心温馨小家Q大街 整套公寓 1室1卫1床\n",
      "0 108 【玖月】海景大2房,Modern 2BR close to shekouferry &airport 整套公寓 2室2卫2床\n",
      "0 87 房子很漂亮—旁边海上世界广场 港澳游出行方便 整套房子 3室1卫3床\n",
      "10 53 【念念】现代公寓 福田CBD 会展中心#私人家庭影院#Coco Park福田皇岗双口岸 岗厦地铁口 整套公寓 1室1卫1床\n",
      "16 58 #从今以后#FNO1.#摄影主题民宿#深圳华侨城#生态北欧民宿#ROOM2 独立房间 1室1卫1床\n",
      "0 413 深圳大鹏林公馆独栋海景别墅一号 整套房子 4室5卫16床\n",
      "1条评价 66 福田中心区近福田高铁站香蜜湖特区报社五洲星苑温馨北欧两房整租 整套房子 2室1卫3床\n",
      "44 61 #一间•寒舍Room4#福田下沙地铁口高层景观公寓,森林极简风,交通便利,私人房间,拍摄请另咨询 独立房间 1室1卫1床\n",
      "0 110 kingkey riverside era apartment two bedrooms两室一厅 整套房子 2室1卫2床\n",
      "11 108 日式风格和古风设计风格的榻榻米艺术空间 整套房子 2室1卫3床\n",
      "52 83 #一间·寒舍Room1#福田CBD下沙地铁口极简风格,无敌景观房,独享大浴缸,私人房间,拍摄请另咨询 独立房间 1室1卫1床\n",
      "58 40 「木夕」地铁口/九方购物中心楼上/深圳北站 /直达福田口岸 全新日式风公寓 整套公寓 1室1卫1床\n",
      "0 157 浪漫小屋高端民宿 整套公寓 单间1卫2床\n",
      "19 48 (往事)罗湖阅见·生活美学公寓城景大床房近地王大厦万象城KKMALL大剧院D出口 整套公寓 1室1卫1床\n",
      "53 61 #一间·寒舍Room 2#福田CBD下沙地铁口极简风,景观房,交通便利,私人房间,拍摄请另咨询 独立房间 1室1卫1床\n",
      "24 100 #BananaHouse香蕉宿#南山西丽地铁口深职院旁毗邻深圳北站大学城,靠近科技园海岸城深圳湾口岸 整套房子 3室2卫4床\n",
      "1条评价 27 地铁口日系小屋低成本便利之选 整套公寓 1室1卫1床\n",
      "29 127 福田景田顶层复式豪宅,248平米,三房三卫。 整间阁楼 4室3卫4床\n",
      "0 50 行动派Home 整套公寓 1室1卫1床\n",
      "9 140 summer+近深圳北聚会轰趴、麻将,团建房简约北欧风 整套公寓 4室3卫4床\n",
      "14 75 #朝夕-Wind林间有风#全景落地窗海景房,270度景观大浴缸,福田CBD下沙地铁口 独立房间 1室1卫1床\n",
      "0 138 福田口岸福朋喜来登豪华大两房17A1(120平,可摄影和聚会) 整套公寓 2室1卫2床\n",
      "69 94 来我的水泥盒子设计工作室撸狗吧 独立房间 1室1卫1床\n",
      "0 68 高尔夫酒店式公寓•静谧美好(拥有深圳五星级酒店都不曾有的风景,超值享有) 整套公寓 2室1卫2床\n",
      "48 23 地鐵房_簡約北歐單間OCT華僑城 独立房间 1室1卫1床\n",
      "65 31 SmileHouse超讚房東_大双床房(两张单人床)115米平方,近香港口岸、石厦站2分,如朋友招待 独立房间 1室1卫2床\n",
      "68 46 【Arch Home】绘造社——景田地铁旁 整套房子 1室1卫1床\n",
      "0 72 世界之窗,欢乐谷,锦绣中华,舒适两房两厅 整套房子 2室1卫2床\n",
      "3 31 新房特惠·罗湖中心双地铁站精品公寓近KKMall大剧院 整套公寓 1室1卫1床\n",
      "0 234 深圳最繁华地段福田中心区四房 整套房子 4室2卫4床\n",
      "117 45 【宫遇】17R-KKmall楼上一房一厅--【Loft时代】 整套公寓 1室1卫1床\n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.firefox.firefox_binary import FirefoxBinary\n",
    "import time\n",
    "\n",
    "caps = webdriver.DesiredCapabilities().FIREFOX\n",
    "caps[\"marionette\"] = True\n",
    "binary = FirefoxBinary(r'D:\\Program Files\\Mozilla Firefox\\firefox.exe')\n",
    "#把上述地址改成你电脑中Firefox程序的地址\n",
    "\n",
    "#用 selenium 的 driver 来启动 firefox\n",
    "driver = webdriver.Firefox(firefox_binary=binary, capabilities=caps)\n",
    "#在虚拟浏览器中打开 Airbnb 页面\n",
    "driver.get(\"https://zh.airbnb.com/s/Shenzhen--China?page=1\")\n",
    "\n",
    "for i in range(0,5):\n",
    "    #找到页面中所有的出租房\n",
    "    rent_list = driver.find_elements_by_css_selector('div._1788tsr0')\n",
    "\n",
    "    #对于每一个出租房\n",
    "    for eachhouse in rent_list:\n",
    "        #找到评论数量\n",
    "        try:\n",
    "            comment = eachhouse.find_element_by_css_selector('span._gb7fydm')\n",
    "            comment = comment.text\n",
    "        except:\n",
    "            comment = 0\n",
    "\n",
    "        #找到价格\n",
    "        price = eachhouse.find_element_by_css_selector('span._hylizj6')\n",
    "        price = price.text[4:]\n",
    "\n",
    "        #找到名称\n",
    "        name = eachhouse.find_element_by_css_selector('div._ew0cqip')\n",
    "        name = name.text\n",
    "\n",
    "        #找到房屋类型，大小\n",
    "        details = eachhouse.find_elements_by_css_selector('div._saba1yg small div span')\n",
    "        details = details[0].text\n",
    "        house_type = details.split(\" · \")[0]\n",
    "        bed_number = details.split(\" · \")[1]\n",
    "        print (comment, price, name, house_type, bed_number)\n",
    "    #下一页\n",
    "    nextpage = driver.find_element_by_css_selector('li._b8vexar').click()\n",
    "    time.sleep(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "12px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
